<?php
header("Content-type:text/html;charset=utf-8");
/**
 *
 */
class Sx_repwd extends CI_Controller {
	var $re_email;
	var $stmp_body = "";

	public function index() {
		if (isset($_POST['user_email']) || !empty($_POST['user_email'])) {
			$this -> re_email = $_POST['user_email'];
			if (preg_match("/^[a-zA-Z0-9_]+@[a-zA-Z0-9-]+.[a-zA-Z0-9]+$/", $this -> re_email)) {
				if ($this -> sx_db_mod ->checkemail_resetpwd($this-> re_email)) {
					//加密地址
					//$this->load->library('fengchaoencode');
					$url = urlencode($this->fengchaoencode->url_base64_encode($this->fengchaoencode->sxtimecode($this -> re_email, $operation = 'ENCODE', $key = '', $expiry = 1800)));
					$this->stmp_body = "请点击下面链接重置密码".base_url()."sx_repwd/resetpassword/".$url."/";
					//邮件地址存在，发邮件到邮件里
					$this -> load -> library('email');
					$from = 'haochike@yeah.net';					
					$to = $this -> re_email;					
					$subject = '好吃客密码重置';
					$body = $this -> stmp_body;
					$config['protocol'] = 'smtp';
					$config['smtp_host'] = 'smtp.yeah.net';
					$config['smtp_user'] = 'haochike';
					$config['smtp_pass'] = 'haochike101';
					$config['smtp_port'] = '25';
					$config['smtp_timeout'] = '5';
					$config['newline'] = "/r/n";
					$config['crlf'] = "/r/n";
					$this -> email -> initialize($config);
					$this -> email -> set_mailtype('html');
					$this -> email -> from($from, '好吃客');
					$this -> email -> to($to);
					$this -> email -> subject($subject);
					$this -> email -> message($body);
					$this -> email -> send();
					
					//print("密码重置邮件已发至您的邮箱，请注意查收");
					print($this -> fengchaoclass -> showhckmsg("0","",$this -> lang -> line('密码重置邮件已发至您的邮箱，请注意查收'), TRUE));
					//echo $this -> email -> print_debugger();
				} else {
					//邮件地址不存在
					print($this -> fengchaoclass -> showhckmsg("","",$this -> lang -> line('hck_resetpwd_email_isset'), TRUE));
				}

			} else {
				//邮件地址不正确
				print($this -> fengchaoclass -> showhckmsg("","",$this -> lang -> line('hck_resetpwd_email_type'), TRUE));
			}
		} else {
			//不能直接访问此页面
			print($this -> fengchaoclass -> showhckmsg("","",$this -> lang -> line('hck_resetpwd_postnull'), TRUE));
		}
	}

	public function resetpassword($u = null) {
		if($u == null){
			
		}else{
			//$this->load->library('fengchaoencode');
			$u = urldecode($this->fengchaoencode->url_base64_decode($u));
			echo $u."<hr>";
			
			 if($this->fengchaoencode->sxtimecode($u, $operation = 'DECODE', $key = '', $expiry = 1800)!=""){
				echo $this->fengchaoencode->sxtimecode($u, $operation = 'DECODE', $key = '', $expiry = 1800);
			}else{
				echo "请求过期";
			}
		}
		
	}

}
?>